package com.mobanker.marketing.manager.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.mobanker.marketing.manager.entity.Plan;
import com.mobanker.marketing.manager.service.IPlanService;

@RestController
@RequestMapping("/plan")
public class PlanController {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private IPlanService planService;

	@RequestMapping(value = "insert", method = RequestMethod.GET)
	public Object insert(@RequestParam String field, @RequestParam String name) {
		System.out.println(field);
		System.out.println(name);
		Plan plan = new Plan();
		plan.setField(field);
		plan.setName(name);
		planService.insert(plan);
		return "insert success";
	}
	
	@RequestMapping(value = "query", method = RequestMethod.GET)
	public Object query(@RequestParam String field, @RequestParam String name) {
		Plan param = new Plan();
		param.setField(field);
		param.setName(name);
		System.out.println(param);
		List<Plan> plans = planService.findByObj(param);
		System.out.println(plans.size());
		for (Plan plan : plans) {
			System.out.println(plan.getName());
		}
		return plans;
	}
	
	@RequestMapping(value = "delete", method = RequestMethod.GET)
	public Object delete(@RequestParam String field) {
		Plan plan = new Plan();
		plan.setField(field);
		planService.delete(plan);
		return "delete success";
	}
}
